package com.gxa.login.controller;

import com.gxa.log.cofig.OperateLogConfig;
import com.gxa.login.service.LoginService;
import com.gxa.login.service.TokenService;
import dto.ResultDTO;
import entity.Member;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/login")
@Api(tags = "登录模块")
public class LoginController {

    @Resource
    private LoginService loginService;

    @Resource
    private TokenService tokenService;

    @ApiOperation(value = "邮箱登录接口")
    @PostMapping("/loginEmail")
    @ApiImplicitParams({
            @ApiImplicitParam(name="memberEmail",value="用户邮箱",required = true),
            @ApiImplicitParam(name = "memberPwd",value = "用户密码",required = true)
    })
    public ResultDTO loginEmail(@RequestBody Member member){
        return loginService.loginByEmail(member);
    }


    @ApiOperation(value = "短息登录接口")
    @PostMapping("/loginPhone")
    @ApiImplicitParams({
            @ApiImplicitParam(name="memberPhone",value="用户电话",required = true),
            @ApiImplicitParam(name = "code",value = "验证码",required = true)
    })
    public ResultDTO loginPhone(@RequestBody Member member){
        return loginService.loginByPhone(member);
    }

    @ApiOperation(value = "发短信接口")
    @PostMapping("/sendCode")
    @ApiImplicitParams({
            @ApiImplicitParam(name="memberPhone",value="用户电话",required = true)
    })
    public ResultDTO sendCode(@RequestBody Member member){
        return loginService.sendCode(member);
    }


    @ApiOperation(value = "验证token接口")
    @PostMapping("/token")
    @ApiImplicitParams({
            @ApiImplicitParam(name="token",value="token",required = true)
    })
    public ResultDTO token(String token){
        return tokenService.tokenVerity(token);
    }
}
